var eum=0;
var page=0;

$(function(){

	Pro.promptList(0);
	Pro.limit();
})
// var button='<button onclick="Pro.promptList(0)" class="layui-btn layui-btn-primary layui-btn-sm" style="margin-top: 21%;margin-left: 20%;"><<返回</button>';
var Pro={
	//提示消息管理
	promptList:function(e,pageSize){
		html="";
		if(e==undefined){
			e=0;
		}else if(pageSize==undefined){
			pageSize=Common.limit;
		}
		$.ajax({
			type:"POST",
			url:request("/org/company/list"),
			data:{
				pageIndex:(e==0?"0":e-1),
				pageSize:pageSize
			},
			dataType:'json',
			async:false,
			success:function(result){
				console.log(result)
				checkRequst(result);
				if(result.data!=null){
					for(var i=0;i<result.data.length;i++){
						html+="<tr><td>"+result.data[i].companyName
						+"</td><td>"+result.data[i].createUserId+"</td><td>"+result.data[i].empNum+"</td><td>"+  UI.getLocalTime(result.data[i].createTime)
						+"</td><td align='center' width='150px'><button class='layui-btn layui-btn layui-btn-normal layui-btn-xs delete' onclick='Pro.queryCompanyMessage(\"" + result.data[i].id + "\",\"" + result.data[i].companyName  + "\")'>公司详情</button></td></tr>";
					}
                    $("#messageList_table").empty();
                    $("#messageList_table").append(html);

                    /*if($("#code").val()==""||$("#code").val()==undefined){
                        $("#messageList_table").empty();
                        $("#messageList_table").append(html);
					}
					if(localStorage.getItem("role")==1){
						$(".btn_add").hide();
						$(".delete").hide();
						$(".update").hide();
					}
					$(".updateBtn").show();
			    	$("#errorMessageList").show();
					$("#addErrorMessage").hide();
					$("#code").val("");*/
				}else{
					layer.msg("暂无数据",{"icon":2});
				}
			}
		})
	},

	// 头部搜索
    findPromptList:function(){
        html="";

        $.ajax({
            type:"POST",
            url:request("/console/messageList"),
            data:{
                keyword:($("#code").val() == null ? null : $("#code").val())
            },
            dataType:'json',
            async:false,
            success:function(result){
            	checkRequst(result);
                if(result.data!=null){
                    $("#pageCount").val(result.data.allPageCount);
                    for(var i=0;i<result.data.pageData.length;i++){
                        html+="<tr><td>"+result.data.pageData[i].code+"</td><td>"+result.data.pageData[i].type
                            +"</td><td>"+result.data.pageData[i].zh+"</td><td>"+result.data.pageData[i].en
                            +"</td><td>"+(result.data.pageData[i].big5==null?"":result.data.pageData[i].big5)
                            +"</td><td align='center' width='150px'><button class='layui-btn layui-btn-danger layui-btn-xs delete' onclick='Pro.deleteErrorMessage(\""
                            +result.data.pageData[i].code+"\")'>删除</button><button class='layui-btn layui-btn-primary layui-btn-xs update' onclick='Pro.updateErrorMessage(\""
                            +result.data.pageData[i].code+"\")'>修改</button></td></tr>";
                    }
                    $("#messageList_table").empty();
                    $("#messageList_table").append(html);
                    $(".updateBtn").show();
                    $("#errorMessageList").show();
                    $("#addErrorMessage").hide();
                    // $("#code").val("");
                    Pro.limit(1);
                }else{
                    layer.msg("暂无数据",{"icon":2});
                }
            }
        })
    },


	//查看详情
    queryCompanyMessage:function(id,name){
        localStorage.setItem("company_componyName",name);
        localStorage.setItem("company_Id",id)
		window.location.href="/pages/console/deparMsg.html";
	},
	//查询单条提示消息
	updateErrorMessage:function(code){
	},

	limit:function(index){
            layui.use('laypage', function(){
                var laypage = layui.laypage;
                console.log($("#pageCount").val());
                //执行一个laypage实例
                laypage.render({
                    elem: 'laypage'
                    ,count: $("#pageCount").val()
					,limit:Common.limit
                    ,limits:Common.limits
                    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                    ,jump: function(obj){
                        console.log(obj)
                        page=obj.curr;
                        if(index == 1){
                            Pro.promptList(index,obj.limit);
                            index = 0;
						}else
                        	Pro.promptList(page,obj.limit)
                    }
                })
            })
	}
}